import Vue from 'vue'
import Vuex from 'vuex'
<<<<<<< HEAD
=======
import netClient from '../network/index'
>>>>>>> aeda2c13c6d9f1bcdcbc764ca2642136ce06f725

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
<<<<<<< HEAD
  },
  mutations: {
  },
  actions: {
=======
    bannerList: [],//首页轮播图
    bargainList: [],//首页砍价
    SelectedList: [],//首页专题
    GoodsList: [],// 首页人气列表
    Details: [],//详情页数据
    reputation: [],// 商品评价
    Classify: [], // 商品分类
    OneList: [],  // 一级分类
    TwoList: [],  // 二 级分类
    TwoListItem: [],// 点击一级切换二级分类
    ListItem:[], // 商品列表
    Selecteditemlist:[] //首页专题详情
  },
  mutations: {
    BANNER(state) {
      netClient
        .Banner({})
        .then((res) => {
          console.log(res)
          state.bannerList = res.data.data
        })
        .catch((res) => {
          console.log(res);
        });
      netClient.bargain({}).then((res) => {
        console.log(res)
        state.bargainList = res.data.data.goodsMap
      })
        .catch((res) => {
          console.log(res);
        });

      netClient.Selected({}).then((res) => {
        // console.log(res.data.data)
        state.SelectedList = res.data.data
      })
        .catch((res) => {
          // console.log(res);
        });

        netClient.Selectedlist({}).then((res) => {
          console.log(res)
          state.Selecteditemlist = res.data.data.data
        })
          .catch((res) => {
            // console.log(res);
          });

      netClient.GoodsList({}).then((res) => {
        // console.log(res.data.data.goodsMap) 
        state.GoodsList = res.data.data.goodsMap
      })
        .catch((res) => {
          // console.log(res);
        });
    },
    GOTOITEM(state, cid) {
      // state.Item = cid
      // console.log(cid.id)
      netClient.Details({ params:{
        id: cid.id
      } }).then((res) => {
        console.log(res.data.data)
        state.Details = res.data.data
      })
        .catch((res) => {
          console.log(res);
        });

      netClient.reputation({params:{ goodsId: 156334 }}).then((res) => {
        // console.log(res)
        state.reputation = res
      })
        .catch((res) => {
          // console.log(res);
        });

    },

    CLASSIFY(state) {
      netClient.classifyList({}).then((res) => {
        // console.log(res.data.data)
        state.Classify = res.data.data
        state.OneList = []
        state.TwoList = []
        state.TwoListItem = []
        state.Classify.forEach((element) => {
          if (element.pid === 0) {
            state.OneList.push(element)
          }
        })
        state.Classify.forEach((element) => {
          if (element.pid !== 0) {
            state.TwoList.push(element)
          }
        })
        state.Classify.forEach((element) => {
          if (element.pid !== 0) {
            state.TwoListItem.push(element)
          }
        })
        // console.log(state.TwoList)
      })
        .catch((res) => {
          // console.log(res);
        });
    },
    CLICKONE(state, item) {
      // console.log(item.type)
      state.TwoListItem = []
      state.TwoList.forEach((element) => {
        if (element.type === item.type + '2') {
          state.TwoListItem.push(element)
        }
      })
    },
    CLICKONEALL(state) {
      state.TwoListItem = state.TwoList
      // console.log(state.TwoListItem)
    },
    LISTITEM(state){
      netClient.ListItem({params:{ page:1,pageSize:20 }}).then((res) => {
        // console.log(res.data.data)
        state.ListItem = res.data.data
      })
        .catch((res) => {
          // console.log(res);
        });
    },
    // ZHUANLIST(state){

    // }

  },
  actions: {
    BANNER(context) {
      context.commit('BANNER')
    },
    GOTOITEM(context, cid) {
      context.commit('GOTOITEM', cid)
    },
    CLASSIFY(context) {
      context.commit('CLASSIFY')
    },
    CLICKONE(context, item) {
      context.commit('CLICKONE', item)
    },
    CLICKONEALL(context) {
      context.commit('CLICKONEALL')
    },
    LISTITEM(context) {
      context.commit('LISTITEM')
    }
    // ZHUANLIST(context) {
    //   context.commit('ZHUANLIST')
    // }
>>>>>>> aeda2c13c6d9f1bcdcbc764ca2642136ce06f725
  },
  modules: {
  }
})
